﻿<Page x:Class="OFX.Aggregator.WpfApplication.StatementSourceListPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:OFX.Aggregator.WpfApplication"
    Title="Account List"
    x:Name="theStatementSourceListPage" Width="Auto" ShowsNavigationUI="True"
    Margin="3">

    <Page.Resources>
        <local:TimeSpanConverter x:Key="TimeSpanConverter" />

        <Style x:Key="ListBoxItemActionButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Margin" Value="0, 3, 3, 3"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="VerticalAlignment" Value="Bottom" />
        </Style>

        <DataTemplate x:Key="StatementSourceDataTemplate" DataType="StatementSource">
            <Border>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel HorizontalAlignment="Left" Grid.Column="0">
                        <Label x:Name="DisplayName" Content="{Binding Path=DisplayName}" />
                        <Label x:Name="LastUpdated" IsEnabled="False" Margin="1cm,0,0,0" Content="{Binding Path=LastUpdate, Converter={StaticResource TimeSpanConverter}}" />
                    </StackPanel>

                    <StackPanel x:Name="StatementSourceActions"
                                Visibility="Hidden"
                                HorizontalAlignment="Right" Grid.Column="1">
                        <StackPanel.Triggers>
                            <EventTrigger RoutedEvent="Mouse.MouseEnter">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation To="1.0" Duration="0:0:0.1"
                                                             Storyboard.TargetName="StatementSourceActions"
                                                             Storyboard.TargetProperty="Opacity"
                                                             AccelerationRatio="0.9"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>

                            <EventTrigger RoutedEvent="Mouse.MouseLeave">
                                <EventTrigger.Actions>
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation To="0.5" Duration="0:0:0.1"
                                                             Storyboard.TargetName="StatementSourceActions"
                                                             Storyboard.TargetProperty="Opacity"
                                                             AccelerationRatio="0.9"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger.Actions>
                            </EventTrigger>
                        </StackPanel.Triggers>

                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Bottom"
                                    Margin="3">
                            <Label>Filter statement from:</Label>
                            <xcdg:DatePicker xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
                                             SelectedDate="{Binding Mode=TwoWay, Path=LowerCap}" />
                        </StackPanel>

                        <StackPanel
                            Orientation="Horizontal"
                            HorizontalAlignment="Right" Margin="3">

                            <Button Command="local:StatementSourceListPage.StatementSource_Fetch" CommandParameter="{Binding ElementName=listBoxStatementSources, Path=SelectedItem}" Name="buttonFetch" Style="{StaticResource ListBoxItemActionButtonStyle}">
                                <Button.Content>Fetch Statement</Button.Content>
                            </Button>
                            <Button Command="local:StatementSourceListPage.StatementSource_Config" CommandParameter="{Binding ElementName=listBoxStatementSources, Path=SelectedItem}" Name="buttonSetupAccount" Style="{StaticResource ListBoxItemActionButtonStyle}">
                                <Button.Content>Setup...</Button.Content>
                            </Button>
                            <Button Command="local:StatementSourceListPage.StatementSource_Delete" CommandParameter="{Binding ElementName=listBoxStatementSources, Path=SelectedItems}" Name="buttonDeleteAccounts" Style="{StaticResource ListBoxItemActionButtonStyle}">
                                <Button.Content>Delete</Button.Content>
                            </Button>
                        </StackPanel>
                    </StackPanel>
                </Grid>
            </Border>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ParallelTimeline>
                                    <DoubleAnimation To="16" Duration="0:0:0.05"
                                                             Storyboard.TargetName="DisplayName"
                                                             Storyboard.TargetProperty="FontSize"
                                                             AccelerationRatio="0.9"/>
                                </ParallelTimeline>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>

                    <DataTrigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ParallelTimeline>
                                    <DoubleAnimation To="12" Duration="0:0:0.05"
                                                             Storyboard.TargetName="DisplayName"
                                                             Storyboard.TargetProperty="FontSize"
                                                             AccelerationRatio="0.9"/>
                                </ParallelTimeline>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>

                    <Setter TargetName="DisplayName" Property="FontWeight" Value="UltraBold"/>
                    <Setter TargetName="DisplayName" Property="Foreground" Value="Blue"/>
                    <Setter TargetName="LastUpdated" Property="Foreground" Value="LightBlue"/>

                    <Setter TargetName="StatementSourceActions" Property="Visibility" Value="Visible"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <Style x:Key="ListBoxItemContainerStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="BorderThickness" Value="0.5"/>
            <Setter Property="BorderBrush" Value="#33FF00FF"/>
            <Setter Property="Margin" Value="2.5"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="OuterBorder" Margin="{TemplateBinding Margin}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" CornerRadius="3" Padding="{TemplateBinding Padding}">
                            <ContentPresenter/>
                        </Border>

                        <ControlTemplate.Triggers>
                            <!--<Trigger Property="IsMouseOver" Value="True">
                                <Setter Property="IsSelected" Value="True"/>
                            </Trigger>-->

                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="Background" Value="{StaticResource SelectedItemBrush}"/>
                                <Setter Property="Cursor" Value="Hand"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>

    <Page.CommandBindings>
        <CommandBinding Command="local:StatementSourceListPage.StatementSource_Fetch" CanExecute="CanFetchStatement" Executed="FetchStatement"/>
        <CommandBinding Command="local:StatementSourceListPage.StatementSource_Delete" CanExecute="CanDeleteStatementSource" Executed="DeleteStatementSource"/>
        <CommandBinding Command="local:StatementSourceListPage.StatementSource_Create" CanExecute="CanCreateStatementSource" Executed="CreateStatementSource"/>
        <CommandBinding Command="local:StatementSourceListPage.StatementSource_Config" CanExecute="CanConfigStatementSource" Executed="ConfigStatementSource"/>
    </Page.CommandBindings>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" MinHeight="32" />
            <RowDefinition Height="Auto" MinHeight="26" />
        </Grid.RowDefinitions>

        <Border CornerRadius="3" BorderThickness="1" BorderBrush="Black" Background="Transparent">
            <Grid>
                <Rectangle Fill="White" Opacity="0.5" />
                <ListBox Name="listBoxStatementSources"
                      ItemsSource="{Binding ElementName=theStatementSourceListPage, Path=StatementSources}"
                      ItemTemplate="{StaticResource StatementSourceDataTemplate}"
                      ItemContainerStyle="{StaticResource ListBoxItemContainerStyle}"
                      HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch"
                      SelectionMode="Single" BorderThickness="0" Background="Transparent"
                      IsSynchronizedWithCurrentItem="True" />
            </Grid>
        </Border>

        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Right">
            <Button Command="local:StatementSourceListPage.StatementSource_Create" Name="buttonSetupNewAccount" Margin="0, 3, 3, 3" Padding="3" Grid.Row="1">New Account...</Button>
        </StackPanel>

        <Label Grid.Row="2">
            <Hyperlink>http://www.codeplex.com/activestatement</Hyperlink>
        </Label>
    </Grid>
</Page>
